package com.durian.affairs.service.impl;

import java.util.Date;
import java.util.List;

import com.durian.affairs.api.vo.UpdatePaymentForm;
import com.durian.common.core.utils.DateUtils;
import com.durian.common.security.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.durian.affairs.mapper.CwPaymentPlanMapper;
import com.durian.affairs.api.domain.CwPaymentPlan;
import com.durian.affairs.service.ICwPaymentPlanService;

/**
 * 付款计划管理Service业务层处理
 * 
 * @author durian
 * @date 2022-06-26
 */
@Service
public class CwPaymentPlanServiceImpl implements ICwPaymentPlanService 
{
    @Autowired
    private CwPaymentPlanMapper cwPaymentPlanMapper;

    /**
     * 查询付款计划管理
     * 
     * @param id 付款计划管理主键
     * @return 付款计划管理
     */
    @Override
    public CwPaymentPlan selectCwPaymentPlanById(Long id)
    {
        return cwPaymentPlanMapper.selectCwPaymentPlanById(id);
    }

    /**
     * 查询付款计划管理列表
     * 
     * @param cwPaymentPlan 付款计划管理
     * @return 付款计划管理
     */
    @Override
    public List<CwPaymentPlan> selectCwPaymentPlanList(CwPaymentPlan cwPaymentPlan)
    {
        return cwPaymentPlanMapper.selectCwPaymentPlanList(cwPaymentPlan);
    }

    /**
     * 新增付款计划管理
     * 
     * @param cwPaymentPlan 付款计划管理
     * @return 结果
     */
    @Override
    public int insertCwPaymentPlan(CwPaymentPlan cwPaymentPlan)
    {
        cwPaymentPlan.setCreateTime(DateUtils.getNowDate());
        return cwPaymentPlanMapper.insertCwPaymentPlan(cwPaymentPlan);
    }

    /**
     * 修改付款计划管理
     * 
     * @param cwPaymentPlan 付款计划管理
     * @return 结果
     */
    @Override
    public int updateCwPaymentPlan(CwPaymentPlan cwPaymentPlan)
    {
        cwPaymentPlan.setUpdateTime(DateUtils.getNowDate());
        return cwPaymentPlanMapper.updateCwPaymentPlan(cwPaymentPlan);
    }

    /**
     * 批量删除付款计划管理
     * 
     * @param ids 需要删除的付款计划管理主键
     * @return 结果
     */
    @Override
    public int deleteCwPaymentPlanByIds(Long[] ids)
    {
        return cwPaymentPlanMapper.deleteCwPaymentPlanByIds(ids);
    }

    /**
     * 删除付款计划管理信息
     * 
     * @param id 付款计划管理主键
     * @return 结果
     */
    @Override
    public int deleteCwPaymentPlanById(Long id)
    {
        return cwPaymentPlanMapper.deleteCwPaymentPlanById(id);
    }

    /**
     * 修改支付信息
     * @param updatePaymentForm
     * @return
     */
    @Override
    public int payForTheOrder(UpdatePaymentForm updatePaymentForm) {
        System.err.println(updatePaymentForm.getPaymentId());
        CwPaymentPlan payment = cwPaymentPlanMapper.selectCwPaymentPlanById(updatePaymentForm.getPaymentId().longValue());
        //支付方式
        payment.setPayMethod(updatePaymentForm.getPayMethod());
        //付款状态
        payment.setPayState(2);
        //付款日期
        payment.setPaidTime(new Date());
        //付款金额
        payment.setRealPaymentAmount(updatePaymentForm.getRealPaymentAmount());
        //更新时间
        payment.setUpdateTime(new Date());
        //更改操作人id
        payment.setUpdateUserid(SecurityUtils.getUserId());
        return cwPaymentPlanMapper.payForTheOrder(payment);
    }
}
